package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.OneParagraphMapper;
import com.yxuan.springboot.model.OneParaRange;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yxuan.springboot.model.OneParagraph;
import com.yxuan.springboot.service.OneParagraphService;

import java.util.List;

/**
 * 
 * @author zchao
 *    OneParagraph业务层实现类
 * @date 2023-05-17 17:19:09
 */
@Service
@Transactional
@Slf4j
public class OneParagraphServiceImpl extends BaseServiceImpl<OneParagraph> implements OneParagraphService {

    @Autowired
    private OneParagraphMapper oneParagraphMapper;

    @Override
    public List<OneParagraph> findClassificationGroup(String province, String year) {
        return oneParagraphMapper.getClassificationGroup(province,year);
    }

    @Override
    public List<OneParagraph> findHistorySame(String score, String province, String classification, String year) {
        return oneParagraphMapper.getHistorySame(score,province,classification,year);
    }

    @Override
    public List<OneParaRange> findRangeNumber(String province, String year, String classification) {
        List<OneParaRange> list = oneParagraphMapper.getRangeNumber(province,year,classification);
        System.out.println("--------------------------------------");
        System.out.println(list);
        System.out.println("--------------------------------------");
        return list;
    }

    @Override
    public String findRankOne(OneParagraph oneParagraph) {
        //根据省份年份查询到所有的选科（文理科等），放进一个集合里
        List<OneParagraph> OneList = this.findClassificationGroup(oneParagraph.getProvince(), oneParagraph.getYear());
        //确定考生的选科（文科，理科，物理类，历史类还是综合）
        String classification = "综合";
        System.out.println("传入数据"+oneParagraph);
        if ((oneParagraph.getClassification().charAt(0) + "").equals("物") || (oneParagraph.getClassification().charAt(0) + "").equals("理")) {
            for (OneParagraph paragraph : OneList) {
                if (paragraph.getClassification().equals("物理类") || paragraph.getClassification().equals("理科")) {
                    classification = paragraph.getClassification();
                }
            }
        } else if ((oneParagraph.getClassification().charAt(0) + "").equals("历") || (oneParagraph.getClassification().charAt(0) + "").equals("文")) {
            for (OneParagraph paragraph : OneList) {
                if (paragraph.getClassification().equals("历史类") || paragraph.getClassification().equals("文科")) {
                    classification = paragraph.getClassification();
                }
            }
        }
        oneParagraph.setClassification(classification);
        log.info("考生选科为："+oneParagraph.toString());
        List<OneParagraph> list = oneParagraphMapper.getHistorySameOne(oneParagraph.getScore(), oneParagraph.getProvince(), oneParagraph.getClassification(), oneParagraph.getYear());
        if (list.size() == 0) {
            return "1000000000";
        }
        return list.get(0).getUpInPeople();
    }

}
